package com.demo02_interaction.client;

import com.demo02_interaction.bean.VideoDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class VideoServiceClientFallbackFactory implements FallbackFactory<VideoServiceClient> {

    @Override
    public VideoServiceClient create(Throwable cause) {
        return new VideoServiceClient() {
            @Override
            public VideoDTO getVideoById(Long videoId) {
                log.error("获取视频信息失败，视频ID: {}", videoId, cause);
                throw new RuntimeException("无法获取视频信息，请稍后重试");
            }

            @Override
            public Boolean checkVideoExists(Long videoId) {
                log.error("检查视频存在失败，视频ID: {}", videoId, cause);
                return false;
            }

            @Override
            public void updateLikeCount(Long videoId, int delta) {
                log.error("更新视频点赞数失败，视频ID: {}, 增量: {}", videoId, delta, cause);
                // 这里可以记录到重试队列或日志中，稍后重试
            }
        };
    }
}

